home *** CD-ROM | disk | FTP | other *** search
- /*
- SNEWS 2.0
-
- snews - posting stuff
-
-
- Copyright (C) 1991 John McCombs, Christchurch, NEW ZEALAND
- john@ahuriri.gen.nz
- PO Box 2708, Christchurch, NEW ZEALAND
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 1, as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- See the file COPYING, which contains a copy of the GNU General
- Public License.
-
- Atari version ported by Graham Judd - gjudd@siward.demon.co.uk
-
- */
-
- /*---------------------------- Source Control ------------------------------*/
-
- /*
- * $Id: post.c,v 1.3 1994/02/10 22:56:02 gbj Exp user $
- */
-
- /****************************************************************************
- * 20 May 92 1.2 GT ka9q posting. *
- * 22 May 92 1.3 GT Make <dow> and <mth> public. *
- * 31 May 92 1.4 GT Fix From:. *
- * 03 Jun 92 1.5 GT Less vigorous quoting. *
- * 08 Jun 92 1.6 GT FQDN in "Path:". *
- * 09 Jun 92 1.7 GT No local posting. *
- * 12 Jun 92 1.8 NJL Configurable quote marks; 50-line mode; *
- * Ensure strtok() accepts tab as well as space. *
- * 16 Jun 92 1.9 GT Post via "mail2news". *
- * 20 Jul 92 1.10 GT Close signature file. *
- * 26 Aug 92 1.11 MSM Snews 1.90 *
- * 18 Oct 92 1.12 TOF Allow empty entries of subj, dist, f-up *
- * 21 Nov 92 1.13 MSM Extra blank line in f0ollowup removed *
- * 29 Dec 92 1.14 MSM Prevent blank Organisation/Reply-to lines *
- * 13 Feb 93 1.15 MSM Re-enable local posting as an option *
- * Change edit to edit whole message *
- * 21 Mar 93 1.16 MSM Allow "mail2news" to be configurable *
- * 2 Jun 93 1.17 MSM Snews 2.0 *
- * 28 Jun 93 1.18 MSM Full edit on first pass *
- * 3 Oct 93 1.19 MSM Extra abort options added *
- * Case sensitive y/n questions made insensitive *
- * 4 Dec 93 1.20 MSM Permit blank organisation *
- * 31 Jan 94 AT2 GBJ Post news via nntp not smtp *
- * 2 Apr 94 1.21 GBJ Followup to poster corrected to not post to *
- * newsgroup poster *
- * Support footer quote for sigs *
- ****************************************************************************/
-
-
-
- #include "defs.h"
- #include "snews.h"
- #include "screen.h"
- #include "locking.h"
-
- #ifdef ATARI
- # include "fileops.h"
- int pass_to_nntp(char *fname);
- #endif
-
- #include <io.h>
- #include <time.h>
-
- char *dow[] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
- };
- char *mth[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
- "Oct", "Nov", "Dec"
- };
-
- /*
- * The first type of marker is as used by View
- * The second the more usual style of blank line
- * Comment out as you wish
- */
-
- //char marker[] = "================================================================================\n";
- char marker[] = "\n";
-
- extern long seqno;
-
- /*------------------------------- post an article --------------------------*/
- int post(TEXT * tx, char *gx, char *subject)
- {
-
- /*
- * Ask for the data we are not given in the arguments, let him edit
- * the article, then post it
- */
-
- FILE *article, *sig, *new_art;
- LINES *ln;
- static char buf[512], buf2[256], buf3[24];
- static char newsgroups[512];
- static char sig_fn[80];
- static char author[80], msg_id[80], r_name[128];
- int ch, lct, header;
- static char oldsubject[256];
- static char followupto[80];
- int rc, success = 0;
- char *ptr;
-
- strcpy(newsgroups, gx);
- if (strlen(newsgroups) > 64) {
- ptr = strchr(newsgroups, ',');
- *ptr = '\0';
- }
-
- strcpy(author, "");
- strcpy(msg_id, "");
- strcpy(followupto, "");
-
- if ((article = fopen("post.tmp", "w+")) != NULL) {
-
- command("");
- lct = 1;
- ch = 'y';
- header = FALSE;
- strcpy(oldsubject, "");
- if (strlen(newsgroups) == 0) {
-
- /* if no groups ask for them */
- lmessage("Newsgroups? ");
- gets(newsgroups);
-
- }
- else {
-
- /* there is a group ask if he wants to change */
- if (tx != NULL) {
- sprintf(buf, "Followup is to %s, post to that group (y/n)?", newsgroups);
- }
- else {
- sprintf(buf, "Group: %s, post to *this* group (y/n)?", newsgroups);
- }
- message(buf);
- do
- {
- ch = getch();
- ch = tolower(ch);
- }
- while ((ch != 'y') && (ch != 'n'));
-
- if (ch == 'n') {
- lmessage("Newsgroups? ");
- gets(newsgroups);
- }
- }
-
- /* check for a valid newsgroups line */
- if (newsgroups_valid(newsgroups)) {
- if (tx != NULL) {
- if (ch == 'y') {
- if (tx->follow_up == NULL)
- strcpy(newsgroups, tx->newsgroup);
- else {
- if (strnicmp(tx->follow_up, "poster", 6) == 0)
- strcpy(newsgroups, tx->newsgroup);
- else
- strcpy(newsgroups, tx->follow_up);
- }
- }
- if (newsgroups[strlen(newsgroups)-1] == '\n')
- newsgroups[strlen(newsgroups)-1] = '\0';
- message("Quote article (y/n/a)? ");
- do
- {
- ch = getch();
- ch = tolower(ch);
- }
- while ((ch != 'y') && (ch != 'n') && (ch != 'a'));
- textbackground(msgb);
- textcolor(msgf);
- putch(ch);
- putch('\n');
- putch('\r');
- textbackground(textb);
- textcolor(textf);
- }
- strcpy(oldsubject, subject);
-
- if (ch == 'a') {
- fclose(article);
- unlink("post.tmp");
- message("*** Article aborted - Press any key ***");
- getch();
- return -1;
- }
- if (strlen(subject) == 0) { /* Subject does not exist */
- lmessage("Subject? ");
- gets(subject);
- }
-
- if (my_stuff.expert == TRUE) {
- lct = post_header(tx, article, newsgroups, subject, msg_id,
- lct);
- header = TRUE;
- }
-
- /* add the quoted message */
- /* are we quoting */
- if (tx != NULL) {
-
- get_his_stuff(tx, author, msg_id, r_name);
-
- if (ch == 'y') {
-
- strcpy(buf2, " ");
- strcpy(buf3, " ");
- if ((strlen(msg_id) + strlen(author) + strlen(r_name)) > 60) {
- strcpy(buf2, "\n ");
- if ((strlen(author) + strlen(r_name)) > 60)
- strcpy(buf3, "\n ");
- }
- fprintf(article, "In article %s%s%s%s%s writes:\n\n", msg_id, buf2, author, buf3, r_name);
- if (my_stuff.header_quote)
- ln = tx->top;
- else
- ln = tx->start;
- while (ln != NULL) {
- if ((strncmp(ln->data, "-- ", 3) == 0) && my_stuff.footer_quote)
- break;
- fprintf(article, "%s%s", my_stuff.quotemark, ln->data);
- ln = ln->next;
- }
- }
- }
-
- /* append the signature if there is one */
- strcpy(sig_fn, my_stuff.home);
- strcat(sig_fn, my_stuff.signature);
- if ((sig = fopen(sig_fn, "rt")) != NULL) {
- if (my_stuff.footer_quote)
- fprintf(article, "\n-- \n");
- else
- fprintf(article, "\n");
- while (fgets(buf, 79, sig) != NULL)
- fputs(buf, article);
-
- (void) fclose(sig);
- }
-
-
- fclose(article);
- ch = 'e';
- while ((ch != 'p') && (ch != 'a')) {
- if (ch == 'e') {
- sprintf(buf, my_stuff.editor, "post.tmp");
- strcpy(buf2, buf);
- if (my_stuff.edit_line != NULL) {
- strcat(buf2, " ");
- if (header == TRUE)
- sprintf(buf, my_stuff.edit_line, lct+1);
- else
- sprintf(buf, my_stuff.edit_line, lct);
- strcat(buf2, buf);
- }
- rc = system(buf2);
- if (rc != 0) {
- success = 0;
- unlink("post.tmp");
- if (strlen(oldsubject) > 0)
- strcpy(subject, oldsubject);
- return success;
- }
- }
-
- if ((my_stuff.expert != TRUE) && (header == FALSE)) {
- if ((article = fopen("post.tmp", "r")) == NULL) {
- success = 0;
- unlink("post.tmp");
- if (strlen(oldsubject) > 0)
- strcpy(subject, oldsubject);
- return success;
- }
- if ((new_art = fopen("new.tmp", "w+")) == NULL) {
- success = 0;
- unlink("post.tmp");
- if (strlen(oldsubject) > 0)
- strcpy(subject, oldsubject);
- return success;
- }
- lct = post_header(tx, new_art, newsgroups, subject,
- msg_id, lct);
- while (fgets(buf, sizeof(buf), article) != NULL) {
- fputs(buf, new_art);
- }
- fclose(article);
- fclose(new_art);
- unlink("post.tmp");
- rename("new.tmp", "post.tmp");
- header = TRUE;
- }
-
- gotoxy(1, scr_rows - 2);
- textbackground(msgb);
- textcolor(msgf);
- clreol();
- cprintf("Post Article to newsgroups ?");
- textbackground(textb);
- textcolor(textf);
- gotoxy(1, scr_rows - 1);
- sprintf(buf, "(P)ost, (E)dit or (A)bort ? (p/e/a):");
- message(buf);
- while (((ch = getch()) != 'p') && (ch != 'a') && (ch != 'e'));
- gotoxy(1, 24);
- }
- gotoxy(1, scr_rows - 2);
- textbackground(msgb);
- textcolor(msgf);
- clreol();
-
- if (ch == 'p') {
- success = post_it("post.tmp", newsgroups);
- message("*** Article posted - Press any key ***");
- getch();
- }
- if (ch == 'a') {
- message("*** Article aborted - Press any key ***");
- getch();
- }
-
- }
-
- fclose(article);
- unlink("post.tmp");
- if (strlen(oldsubject) > 0)
- strcpy(subject, oldsubject);
-
- }
- else {
- message("*** couldn't open temp article file - press any key ***");
- getch();
- success = 0;
- }
-
- return success;
- }
- /*----------------------- Add Article Header ------------------------------*/
- int post_header(TEXT *tx, FILE *article, char *newsgroups,
- char *subject, char *msg_id, int lct)
- {
- struct tm *gmt;
- time_t t;
- char *p;
- static char distribution[80];
- char buf[256];
- char author[80], r_name[128];
-
- if ((tx != NULL) && (tx->distribution != NULL))
- strcpy(distribution, tx->distribution);
- else
- strcpy(distribution, "");
-
- if (strlen(distribution) > 0)
- if (distribution[strlen(distribution)-1] == '\n')
- distribution[strlen(distribution)-1] = '\0';
-
- fprintf(article, "Path: %s.%s!%s\n", my_stuff.my_site,
- my_stuff.my_domain, my_stuff.user);
- lct++;
- fprintf(article, "From: %s@%s.%s (%s)\n", my_stuff.user,
- my_stuff.my_site, my_stuff.my_domain, my_stuff.my_name);
- lct++;
- #ifndef ATARI
- fprintf(article, "To: %s@%s\n", my_stuff.mail_id, my_stuff.mail_server);
- lct++;
- fprintf(article, "Cc: \n");
- lct++;
- fprintf(article, "Bcc: \n");
- lct++;
- #endif
- fprintf(article, "Newsgroups: ");
- strcpy(buf, newsgroups);
- p = strtok(buf, " \t,");
- if (p != NULL) {
- fprintf(article, "%s", p);
- p = strtok(NULL, " \t,");
- }
- while (p != NULL) {
- fprintf(article, ",\n %s", p);
- lct++;
- p = strtok(NULL, " \t,");
- }
- fprintf(article, "\n");
- lct++;
- if (tx != NULL)
- get_his_stuff(tx, author, msg_id, r_name);
- if ((strlen(msg_id) > 0) && strnicmp(subject, "re: ", 4) != 0)
- fprintf(article, "Subject: Re: %s\n", subject);
- else
- fprintf(article, "Subject: %s\n", subject);
- lct++;
-
- if (strlen(distribution) > 0)
- if (distribution[0] != ' ') {
- fprintf(article, "Distribution: %s\n", distribution);
- lct++;
- }
- #ifdef ATARI
- time(&t);
- gmt=gmtime(&t);
- sprintf(buf,
- "Message-ID: <%02d%02d%02dZ%02d%02d%02d.%03d%s@%s.%s>",
- gmt->tm_year % 100, gmt->tm_mon+1, gmt->tm_mday,
- gmt->tm_hour, gmt->tm_min, gmt->tm_sec, clock() % 1000,
- my_stuff.user, my_stuff.my_site, my_stuff.my_domain);
- #else
- sprintf(buf, "Message-ID: <%ldsnz@%s.%s>",
- time(&t), my_stuff.my_site, my_stuff.my_domain);
- #endif
- fprintf(article, "%s\n", buf);
- lct++;
-
- if (strlen(msg_id) > 0) {
- if ((tx != NULL) && (tx->references != NULL) && (strlen(tx->references) < 240)) {
- strcpy(buf, tx->references);
- if (buf[strlen(buf)-1] == '\n')
- buf[strlen(buf)-1] = '\0';
- fprintf(article, "References: %s %s\n", buf, msg_id);
- }
- else
- fprintf(article, "References: %s\n", msg_id);
- lct++;
- }
- #ifndef ATARI
- time(&t);
- gmt=gmtime(&t);
- #endif
- fprintf(article, "Date: %s, %02d %s %02d %02d:%02d:%02d GMT\n",
- dow[gmt->tm_wday],
- gmt->tm_mday, mth[gmt->tm_mon], (gmt->tm_year % 100),
- gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
- lct++;
-
- #ifdef ATARI
- if (my_stuff.my_organisation != NULL)
- if (strlen(my_stuff.my_organisation) > 0)
- fprintf(article, "Organization: %s\n", my_stuff.my_organisation);
- else
- fprintf(article, "Organization: \n");
- else
- fprintf(article, "Organization: \n");
- #else
- if ((my_stuff.my_organisation != NULL) && (strlen(my_stuff.my_organisation) > 0))
- fprintf(article, "Organization: %s\n", my_stuff.my_organisation);
- else
- fprintf(article, "Organization: \n");
- #endif
- lct++;
-
- if (my_stuff.replyuser != '\0') {
- fprintf(article, "Reply-To: %s\n", my_stuff.replyuser);
- lct++;
- }
-
- fprintf(article, "Followup-To: \n");
- lct++;
-
- fprintf(article, "X-Newsreader: %s\n", VERSION);
- lct++;
-
- fprintf(article, "%s", marker);
-
- return lct;
- }
-
- /*--------------------------- post an article ---------------------------*/
- int post_it(char *artfile, char *newsgroups)
- {
-
- /*
- * Post an article. The article is passed as a closed file, a
- * line count is added and the article sent. The article file is
- * however open on return, to be close by post and deleted if no
- * longer required.
- *
- * Note that the newsgroups and subject passed are those given
- * before the article was edited and may have been changed.
- *
- * The Atari port creates article files suitable for direct posting
- * via nntp rather than mailing mail files.
- */
-
- FILE *article, *tmp, *local;
- FILE *seq_fp;
- static char buf[256], buf2[256];
- char *p, msgid[80];
- static char ng[512], subject[128];
- static char short_d_name[20];
- int ct, in_header;
- int junk_flag;
- long where;
- time_t t;
- ACTIVE *gp;
- int success = 0;
- int m;
- char *new_read;
- #ifndef ATARI
- WRK_FILE *wrk;
- #endif
-
- ct = 0;
- time(&t);
-
- strcpy(buf, my_stuff.spooldir);
- strcat(buf, "sequence.seq");
- if (mlock(my_stuff.spooldir, "sequence", "Snews") != 0) {
- message("*** Couldn't lock sequence file - press any key ***");
- getch();
- return 0;
- }
- if ((seq_fp = fopen(buf, "r+")) == NULL) {
- message("*** Coundn't open mail sequence file - press any key ***");
- getch();
- return 0;
- }
- /* Get the next sequence number */
- rewind(seq_fp);
- fscanf(seq_fp, "%ld", &seqno);
- seqno++;
- rewind(seq_fp);
- fprintf(seq_fp, "%ld\n", seqno);
- fclose(seq_fp);
- rmlock(my_stuff.spooldir, "sequence", "Snews");
-
- #ifndef ATARI
- if ((wrk = parse(artfile, FALSE)) == NULL)
- return 0;
-
- pass_to_smtp(artfile, wrk, FALSE);
- #else
- if (!pass_to_nntp(artfile))
- return 0;
- #endif
-
- if ((article = fopen(artfile ,"rt")) == NULL) {
- message("*** couldn't open temp article file - press any key ***");
- getch();
- return 0;
- }
-
- if (my_stuff.localpost == 1) {
- /* ok, now post it locally */
- /* count the lines */
- rewind(article);
- ct = 0;
- in_header = TRUE;
- while (fgets(buf, 255, article) != NULL) {
- if ((strncmp(buf, marker, 80) == 0) && (in_header == TRUE)) {
- in_header = FALSE;
- }
- if (in_header == FALSE)
- ct++;
- }
- ct--;
-
- sprintf(short_d_name, "D.%.3s", my_stuff.my_site);
- if ((tmp = fopen(short_d_name, "w+/*b*/")) != NULL) {
-
- /* copy the rest */
- rewind(article);
- in_header = TRUE;
- while (fgets(buf, 255, article) != NULL) {
- where = ftell(article);
- if ((in_header == TRUE) && (strncmp(buf, marker, 80) == 0)) {
- sprintf(buf, "Lines: %d\n\n", ct);
- in_header = FALSE;
- }
- if ((strnicmp(buf, "BC:", 3) == 0) && (in_header == TRUE))
- continue;
- if ((strnicmp(buf, "BCC:", 4) == 0) && (in_header == TRUE))
- continue;
- if ((strnicmp(buf, "Subject:", 8) == 0) && (in_header == TRUE)) {
- strcpy(subject, buf+9);
- if (subject[strlen(subject)-1] != '\0')
- subject[strlen(subject)-1] = '\0';
- }
- if ((strnicmp(buf, "Message-ID:", 11) == 0) && (in_header == TRUE)) {
- strcpy(msgid, buf+12);
- if (msgid[strlen(msgid)-1] == '\n')
- msgid[strlen(msgid)-1] = '\0';
- }
- if ((strnicmp(buf, "Newsgroups:", 11) == 0) && (in_header == TRUE)) {
- strcpy(ng, buf+12);
- if (ng[strlen(ng)-1] == '\n')
- ng[strlen(ng)-1] = '\0';
- do
- {
- if (fgets(buf2, 255, article) != NULL) {
- if (buf2[0] == ' ') {
- strcat(ng, buf2);
- if (ng[strlen(ng)-1] == '\n')
- ng[strlen(ng)-1] = '\0';
- }
- }
- else
- buf2[0] = '\0';
- }
- while (buf2[0] == ' ');
- }
- if ((in_header == TRUE) && (buf[0] != ' ')) {
- strcpy(buf2, buf);
- p = strtok(buf2, ":");
- p = strtok(NULL, " \t");
- if (p != NULL)
- if (strcmp(p, "\n") == 0)
- continue;
- }
- fputs(buf, tmp);
- fseek(article, where, SEEK_SET);
- }
-
- p = strtok(ng, " ,\t");
- while (p != NULL) {
-
- rewind(tmp);
-
- local = open_out_file(p, &junk_flag);
- where = ftell(local);
- while (fgets(buf, 255, tmp) != NULL) {
- fputs(buf, local);
- }
- fprintf(local, "\n@@@@END\n");
- fclose(local);
- gp = find_news_group(p, &junk_flag);
-
- /* update the read list */
- ct = (int) (gp->hi_num - gp->lo_num);
- new_read = (char *) malloc(ct * sizeof(int));
- for (m=0;m<ct-1;m++) {
- *(new_read + m) = *(gp->read_list + m);
- }
- if (my_stuff.localread != 1)
- *(new_read + ct - 1) = FALSE;
- else
- *(new_read + ct - 1) = TRUE;
- free(gp->read_list);
- gp->read_list = new_read;
-
- /* save the data in the index file */
- local = open_index_file(p);
- fprintf(local, "%08ld %08ld %09ld %s\n", where, gp->hi_num, t,
- subject);
- fclose(local);
-
- p = strtok(NULL, " ,\t");
-
- }
- /* now update the snews history */
- open_hist_file();
- add_hist_record(msgid, newsgroups);
- close_hist_file();
-
- /* now don't forget nntp history */
- sprintf(buf, "%shistory.lck", my_stuff.nntp_dir);
- if ((local = fopen(buf, "rt")) != NULL) {
- fclose(local); /* Lock present - can't update */
- }
- else {
- sprintf(buf, "%shistory", my_stuff.nntp_dir);
- local = fopen(buf, "at");
- fputs(msgid, local);
- fputs("\n", local);
- fclose(local);
- }
- /* Yes I know I am ignoring errors here ! it seems appropriate */
- }
- else {
- message("*** couldn't open temp post file - press any key ***");
- getch();
- success = 0;
- return success;
- }
- fclose(tmp);
- unlink(short_d_name);
- }
- success = 1;
- return success;
- }
-
-
-
- /*------------------------ parse and check newsgroups ---------------------*/
- int newsgroups_valid(char *ng)
- {
-
- /*
- * This routine parses the newsgroup list, and checks them for validity
- */
-
- static char buf[256], msg[128];
- char *p;
-
- strcpy(buf, ng);
-
- if ((p = strtok(buf, ", \t")) == NULL)
- return (FALSE);
-
- while (p != NULL) {
- if (!check_valid_post_group(p)) {
- sprintf(msg, "** Can't post to %s **", p);
- message(msg);
- command("-- Press any key to continue --");
- getch();
- return (FALSE);
- }
- p = strtok(NULL, ", \t");
- }
-
- return (TRUE);
- }
-
- #ifdef ATARI
-
- /****************************************************************************
- Parse NNTP message and queue for transmission - ATARI only
- *****************************************************************************/
- /*
- * NOTE: 940210 GBJ Changed success return to 1 and error return to 0.
- */
- int pass_to_nntp(char *fname)
- {
- int isfrom, isnewsgps, isid, need_edit;
- int isnottoken, in_header, ch, line_ct;
- char *p;
- char buff[512];
- char nwgrp[512], msgid[512];
- FILE *fp, *logfp, *txtfp, *wrkfp;
- time_t t;
- struct tm *gmt;
-
-
- isfrom = isnewsgps = isid = need_edit = FALSE;
-
- if ((fp = fopen(fname, "rt")) == NULL) {
- message("*** Cannot open news file - press any key to continue ***");
- getch();
- return 0; /* give up */
- }
-
- /*
- Check that all the required headers are in place - run editor and
- re-scan the headers if not
- */
-
- do {
- need_edit = FALSE;
- in_header = TRUE;
- isnottoken = FALSE;
-
- while (fgets(buff, 511, fp) != NULL) {
- if (strncmp(buff, marker, 80) == 0) {
- in_header = FALSE;
- break;
- }
- if (in_header == TRUE) {
- if ((strnicmp(buff, "FROM:", 5) == 0) && (strlen(buff) > 8))
- isfrom = TRUE;
-
- if ((strnicmp(buff, "MESSAGE-ID:", 11) == 0) && (strlen(buff) > 14)) {
- isid = TRUE;
- strncpy(msgid, buff + 12, strlen(buff) - 11);
- }
- if ((strnicmp(buff, "NEWSGROUPS:", 11) == 0) && (strlen(buff) > 14)) {
- isnewsgps = TRUE;
- strncpy(nwgrp, buff + 12, strlen(buff) - 11);
- }
-
- if ((strchr(buff, ':') == NULL) && (buff[0] != ' '))
- isnottoken = TRUE;
- }
- }
-
- if (in_header == TRUE) {
- message("*** End of header not found - press any key ***");
- getch();
- need_edit = TRUE;
- }
-
- if (isnottoken == TRUE) {
- message("*** Invalid header line found - press any key ***");
- getch();
- need_edit = TRUE;
- }
-
- if (isfrom == FALSE) {
- message("*** No 'From:' line in header - press any key ***");
- getch();
- need_edit = TRUE;
- }
-
- if (isid == FALSE) {
- message("*** No 'Message-ID:' line in header - press any key ***");
- getch();
- need_edit = TRUE;
- }
- if (isnewsgps == FALSE) {
- message("*** No 'Newsgroups:' line in header - press any key ***");
- getch();
- need_edit = TRUE;
- }
-
- if (need_edit == TRUE) {
- fclose(fp);
- message("(E)dit or (A)bort (e/a) ? ");
-
- do {
- ch = getch();
- ch = tolower(ch);
- } while((ch != 'e') && (ch != 'a'));
-
- if (ch == 'a')
- return 0; /* no edit so abort */
-
- sprintf(buff, my_stuff.editor, fname);
- system(buff);
-
- if ((fp = fopen(fname, "rt")) == NULL) {
- message("*** Unable to open news file - press any key ***");
- getch();
- return 0;
- }
- }
- } while(need_edit == TRUE); /* loop until all headers found */
-
- /* Count the lines in the body of the article */
-
- rewind(fp);
- in_header = TRUE;
- while (fgets(buff, sizeof(buff), fp) != NULL) {
- if ((strncmp(buff, marker, 80) == 0) && (in_header == TRUE)) {
- in_header = FALSE;
- line_ct = 0;
- }
- if (in_header == FALSE)
- line_ct++;
- }
- line_ct--;
-
- /* look for and open the local log file */
-
- logfp = NULL;
-
- if (stricmp(my_stuff.mailuser, "none") != 0) {
- sprintf(buff, "%s%s.txt", my_stuff.mail_dir, my_stuff.mailuser);
- if ((logfp = fopen(buff, "at")) == NULL) {
- message("*** unable to open post log file - press any key ***");
- getch(); /* this is not a fatal error */
- }
-
- time(&t);
- gmt = gmtime(&t);
- fprintf(logfp, "From %s@%s.%s ", my_stuff.user, my_stuff.my_site,
- my_stuff.my_domain);
- fprintf(logfp, "%s, %02d %s %02d %02d:%02d:%02d GMT\n",
- dow[gmt->tm_wday],
- gmt->tm_mday, mth[gmt->tm_mon], (gmt->tm_year % 100),
- gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
- }
-
- /* create the nntp text file with a .txt suffix */
-
- sprintf(buff, "%s\\%ld.txt", my_stuff.spooldir, seqno);
- if ((txtfp = fopen(buff, "w")) == NULL) {
- message("*** unable to create nntp text file - press any key ***");
- getch();
- if (logfp != NULL)
- fclose(logfp);
- return 0;
- }
-
- rewind(fp);
- in_header = TRUE;
-
- while (fgets(buff, sizeof(buff), fp) != NULL) {
- if (in_header) {
- if (strncmp(buff, "Followup-To: \n", 14) == 0) {
- continue; /* Don't write a blank line */
- }
- if (strncmp(buff, marker, 80) == 0) {
- sprintf(buff, "Lines: %d\n\n", line_ct);
- in_header = FALSE;
- }
- }
-
- fputs(buff, txtfp); /* copy line to article file */
-
- if (logfp != NULL)
- fputs(buff, logfp); /* copy line to log file */
- }
-
- fclose(fp); /* close the temp article file */
- fclose(txtfp); /* close the nntp article file */
-
- if (logfp != NULL)
- fclose(logfp); /* close log file */
-
- /* create the nntp work file with a .nwk suffix */
-
- sprintf(buff, "%s\\%ld.nwk", my_stuff.spooldir, seqno);
-
- if ((wrkfp = fopen(buff, "w")) == NULL) {
- message("*** unable to create nntp work file - press any key ***");
- getch();
- return 0;
- }
-
- fprintf(wrkfp, "%s", msgid); /* print msgid in work file */
-
- for (p = nwgrp; *p; p++) { /* scan for ',' and translate */
- if (*p == ',') /* into '\n' */
- *p = '\n';
- }
-
- fprintf(wrkfp, "%s\n", nwgrp); /* print news groups 1 per line */
-
- fclose(wrkfp); /* close the work file */
-
- return 1; /* return, all OK */
- }
-
- #endif
-
-